/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * uniview
 * Copyright (C) Michael Josef Beer 2010 <michael.josef.beer@googlemail.com>
 * 
 * uniview is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * uniview is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "Projection.h"


namespace uniview {
    
   double *Projection::project(double *point) {
      return this->func(point, this->fov, this->params);
   };
   
   void Projection::setFOV(double angle) {
      this->fov = angle;
   };
   
   
   void Projection::setResolution(int x, int y) {
      this->x = x;
      this->y = y;
   };
   
   
   double *Projection::fisheyeProjection(double *point, double *res) {
      double angley, anglez;
      
      if(point[0] != 0.0) {
         angley = atan(point[1] / point[0]);
         anglez = atan(point[2]/point[0]);
      } else {
         if(point[1] > 0.0) angley = M_PI / 2.0;
         if(point[1] < 0.0) angley = - M_PI / 2.0;
         if(point[2] > 0.0) anglez = M_PI / 2.0;
         if(point[2] < 0.0) anglez = - M_PI / 2.0;
         if(point[1] == 0.0) angley = 0.0;
         if(point[2] == 0.0) anglez = 0.0;
      };

      res[0] = angley / fov * this->x;
      res[1] = anglez / fov * this->y;
      return res;
   };
   
   
   double *Projection::plainProjection(double *point, double *res) {
      if(point[0] == 0.0) {
         res[0] = res[1] = -1.0;
         return res;
      };
      res[0] = point[0] / f;
      res[1] = res[0] * point[2];
      res[0] *= point[1];
      return res;
   };
   
   
   void Projection::setRemainingParams(double *params) {
      this->params;
   };
      
};

